<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>SensitiveParameter 类</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.return-type-will-change.html">« ReturnTypeWillChange</a></li>
      <li style="float: right;"><a href="context.html">上下文（Context）选项和参数 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="reserved.attributes.html">预定义注解</a></li>
    <li>SensitiveParameter 类</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.sensitive-parameter" class="reference">
 <h1 class="title">SensitiveParameter 类</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 8 &gt;= 8.2.0)</p>

  <div class="section" id="sensitive-parameter.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    
    该注解用于标记敏感参数，如果出现在栈跟踪中，则应编辑其值。
   </p>
  </div>

  <div class="section" id="sensitive-parameter.synopsis">
   <h2 class="title">类摘要</h2>

   <div class="classsynopsis">
    <div class="ooclass">
     
    </div>

    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">final</span>
      <span class="modifier">class</span> <strong class="classname">SensitiveParameter</strong>
     </span>
     {</div>
   }</div>

  </div>

  <div class="section">
   <h2 class="title">范例</h2>
   <div class="example" id="example-410">
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">defaultBehavior</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">string&nbsp;$secret</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">string&nbsp;$normal<br /></span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">Exception</span><span style="color: #007700">(</span><span style="color: #DD0000">'Error!'</span><span style="color: #007700">);<br />}<br /><br />function&nbsp;</span><span style="color: #0000BB">sensitiveParametersWithAttribute</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">#[\SensitiveParameter]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">string&nbsp;$secret</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">string&nbsp;$normal<br /></span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">Exception</span><span style="color: #007700">(</span><span style="color: #DD0000">'Error!'</span><span style="color: #007700">);<br />}<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">defaultBehavior</span><span style="color: #007700">(</span><span style="color: #DD0000">'password'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'normal'</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">sensitiveParametersWithAttribute</span><span style="color: #007700">(</span><span style="color: #DD0000">'password'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'normal'</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>上述示例在 PHP 8.2 中的输出类似于于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Exception: Error! in example.php:7
Stack trace:
#0 example.php(19): defaultBehavior(&#039;password&#039;, &#039;normal&#039;)
#1 {main}

Exception: Error! in example.php:15
Stack trace:
#0 example.php(25): sensitiveParametersWithAttribute(Object(SensitiveParameterValue), &#039;normal&#039;)
#1 {main}
</pre></div>
    </div>
   </div>
  </div>

  <div class="section" id="sensitive-parameter.seealso">
   <h2 class="title">参见</h2>
   <p class="para"><a href="language.attributes.html" class="link">注解概览</a></p>
  </div>

 </div>

</div>
</div></div></body></html>